Now that I've streamlined the MCMC process, I am going to submit multiple chains simultaneously. This notebook will make multiple, similar config files, for broad comparison.
This may be rolled into pearce as a helper function, I haven't decided.
For rmin 0, 0.5, 1.0:
For no ab, HSAB and CorrAB emu:
Vpeak sham
Mpeak sham
HOD
HSAB HOD
In [1]:
import yaml
import copy
from os import path
import numpy as np
In [2]:
orig_cfg_fname = '/home/users/swmclau2/Git/pearce/bin/mcmc/nh_gg_sham_hsab_mcmc_config.yaml'
with open(orig_cfg_fname, 'r') as yamlfile:
orig_cfg = yaml.load(yamlfile)
In [3]:
orig_cfg
Out[3]:
In [4]:
#this will enable easier string formatting
sbatch_template = """#!/bin/bash
#SBATCH --job-name={jobname}
#SBATCH --time=24:00:00
#SBATCH -p kipac,iric
#SBATCH -o /home/users/swmclau2/Git/pearce/bin/mcmc/config/{jobname}.out
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=16
###SBATCH --exclusive
module load python/2.7.13
module load py-scipystack
module load hdf5/1.10.0p1
module load py-numpy
python /home/users/swmclau2/Git/pearce/pearce/inference/initialize_mcmc.py {jobname}.yaml
python /home/users/swmclau2/Git/pearce/pearce/inference/run_mcmc.py {jobname}.yaml
"""
In [5]:
r_bins = np.logspace(-1, 1.6, 19)
In [6]:
emu_names = ['HOD','HSAB','CAB','CorrAB']
emu_fnames = [['/home/users/swmclau2/scratch/wp_zheng07/PearceWpCosmo.hdf5', '/home/users/swmclau2/scratch/ds_zheng07/PearceDsCosmo.hdf5'],\
['/home/users/swmclau2/scratch/wp_hsab/PearceWpHSABCosmo.hdf5', '/home/users/swmclau2/scratch/ds_hsab/PearceDsHSABCosmo.hdf5'],
['/home/users/swmclau2/scratch/wp_cab/PearceWpCABCosmo.hdf5', '/home/users/swmclau2/scratch/ds_cab/PearceDsCABCosmo.hdf5'],
['/home/users/swmclau2/scratch/wp_corrab/PearceWpCorrABCosmo.hdf5', '/home/users/swmclau2/scratch/ds_corrab/PearceDsCorrABCosmo.hdf5']]
In [7]:
meas_cov_fname = '/home/users/swmclau2/Git/pearce/bin/covmat/wp_ds_full_covmat.npy'
# TODO replace with actual ones onace test boxes are done
emu_cov_fnames = [['/home/users/swmclau2/Git/pearce/bin/optimization/wp_hod_emu_cov_lpw.npy',
'/home/users/swmclau2/Git/pearce/bin/optimization/ds_hod_emu_cov_lpw.npy'],
['/home/users/swmclau2/Git/pearce/bin/optimization/wp_hsab_emu_cov_lpw.npy',
'/home/users/swmclau2/Git/pearce/bin/optimization/ds_hsab_emu_cov_lpw.npy'],
['/home/users/swmclau2/Git/pearce/bin/optimization/wp_cab_emu_cov_lpw.npy',
'/home/users/swmclau2/Git/pearce/bin/optimization/ds_cab_emu_cov_lpw.npy'],
['/home/users/swmclau2/Git/pearce/bin/optimization/wp_corrab_emu_cov_lpw.npy',
'/home/users/swmclau2/Git/pearce/bin/optimization/ds_corrab_emu_cov_lpw.npy']]
In [8]:
n_walkers = 250
n_steps = 100000
In [9]:
tmp_cfg = copy.deepcopy(orig_cfg)
directory = "/home/users/swmclau2/Git/pearce/bin/mcmc/config/"
output_dir = "/home/users/swmclau2/scratch/PearceMCMC/"
jobname_template = "VpeakSHAM_wp_ds_rmin_{rmin}_{emu_name}"
for rmin in [None, 0.5, 1.0, 2.0]:
for emu_fname, emu_name, emu_cov in zip(emu_fnames, emu_names, emu_cov_fnames):
if rmin is not None:
tmp_cfg['emu']['fixed_params'] = {'z': 0.0, 'rmin':rmin}
tmp_cfg['emu']['training_file'] = emu_fname
tmp_cfg['emu']['emu_type'] = ['LemonPepperWet' for i in xrange(len(emu_fname))]
tmp_cfg['emu']['emu_cov_fname'] = emu_cov
tmp_cfg['data']['true_data_fname']= ['/home/users/swmclau2/Git/pearce/bin/mock_measurements/SHAMmock_wp.npy',
'/home/users/swmclau2/Git/pearce/bin/mock_measurements/SHAMmock_ds.npy']
tmp_cfg['data']['true_cov_fname'] = meas_cov_fname
tmp_cfg['data']['obs']['obs'] = ['wp','ds']
tmp_cfg['data']['obs']['rbins'] = list(r_bins)
tmp_cfg['chain']['nsteps'] = n_steps
tmp_cfg['chain']['nwalkers'] = n_walkers
tmp_cfg['chain']['mcmc_type'] = 'normal'
tmp_cfg['data']['sim']['sim_hps']['system'] = 'sherlock'
tmp_cfg['data']['cov']['emu_cov_fname'] = tmp_cfg['emu']['emu_cov_fname']
tmp_cfg['data']['cov']['meas_cov_fname'] = tmp_cfg['data']['true_cov_fname']
jobname = jobname_template.format(rmin=rmin, emu_name=emu_name)
tmp_cfg['fname'] = path.join(output_dir, jobname+'.hdf5')
with open(path.join(directory, jobname +'.yaml'), 'w') as f:
yaml.dump(tmp_cfg, f)
with open(path.join(directory, jobname + '.sbatch'), 'w') as f:
f.write(sbatch_template.format(jobname=jobname))
In [10]:
tmp_cfg = copy.deepcopy(orig_cfg)
directory = "/home/users/swmclau2/Git/pearce/bin/mcmc/config/"
output_dir = "/home/users/swmclau2/scratch/PearceMCMC/"
jobname_template = "NFWizedSHAM_wp_ds_rmin_{rmin}_{emu_name}"
for rmin in [None, 0.5, 1.0, 2.0]:
for emu_fname, emu_name, emu_cov in zip(emu_fnames, emu_names, emu_cov_fnames):
if rmin is not None:
tmp_cfg['emu']['fixed_params'] = {'z': 0.0, 'rmin':rmin}
tmp_cfg['emu']['training_file'] = emu_fname
tmp_cfg['emu']['emu_type'] = ['LemonPepperWet' for i in xrange(len(emu_fname))]
tmp_cfg['emu']['emu_cov_fname'] = emu_cov
tmp_cfg['data']['true_data_fname']= ['/home/users/swmclau2/Git/pearce/bin/mock_measurements/NFWIZED_SHAMmock_wp.npy',
'/home/users/swmclau2/Git/pearce/bin/mock_measurements/NFWIZED_SHAMmock_ds.npy']
tmp_cfg['data']['true_cov_fname'] = meas_cov_fname
tmp_cfg['data']['obs']['obs'] = ['wp','ds']
tmp_cfg['data']['obs']['rbins'] = list(r_bins)
tmp_cfg['chain']['nsteps'] = n_steps
tmp_cfg['chain']['nwalkers'] = n_walkers
tmp_cfg['chain']['mcmc_type'] = 'normal'
tmp_cfg['data']['sim']['sim_hps']['system'] = 'sherlock'
tmp_cfg['data']['cov']['emu_cov_fname'] = tmp_cfg['emu']['emu_cov_fname']
tmp_cfg['data']['cov']['meas_cov_fname'] = tmp_cfg['data']['true_cov_fname']
jobname = jobname_template.format(rmin=rmin, emu_name=emu_name)
tmp_cfg['fname'] = path.join(output_dir, jobname+'.hdf5')
with open(path.join(directory, jobname +'.yaml'), 'w') as f:
yaml.dump(tmp_cfg, f)
with open(path.join(directory, jobname + '.sbatch'), 'w') as f:
f.write(sbatch_template.format(jobname=jobname))
In [11]:
tmp_cfg = copy.deepcopy(orig_cfg)
directory = "/home/users/swmclau2/Git/pearce/bin/mcmc/config/"
output_dir = "/home/users/swmclau2/scratch/PearceMCMC/"
jobname_template = "ShuffledSHAM_wp_ds_rmin_{rmin}_{emu_name}"
for rmin in [None, 0.5, 1.0, 2.0]:
for emu_fname, emu_name, emu_cov in zip(emu_fnames, emu_names, emu_cov_fnames):
if rmin is not None:
tmp_cfg['emu']['fixed_params'] = {'z': 0.0, 'rmin':rmin}
tmp_cfg['emu']['training_file'] = emu_fname
tmp_cfg['emu']['emu_type'] = ['LemonPepperWet' for i in xrange(len(emu_fname))]
tmp_cfg['emu']['emu_cov_fname'] = emu_cov
tmp_cfg['data']['true_data_fname']= ['/home/users/swmclau2/Git/pearce/bin/mock_measurements/SHUFFLED_SHAMmock_wp.npy',
'/home/users/swmclau2/Git/pearce/bin/mock_measurements/SHUFFLED_SHAMmock_ds.npy']
tmp_cfg['data']['true_cov_fname'] = meas_cov_fname
tmp_cfg['data']['obs']['obs'] = ['wp','ds']
tmp_cfg['data']['obs']['rbins'] = list(r_bins)
tmp_cfg['chain']['nsteps'] = n_steps
tmp_cfg['chain']['nwalkers'] = n_walkers
tmp_cfg['chain']['mcmc_type'] = 'normal'
tmp_cfg['data']['sim']['sim_hps']['system'] = 'sherlock'
tmp_cfg['data']['cov']['emu_cov_fname'] = tmp_cfg['emu']['emu_cov_fname']
tmp_cfg['data']['cov']['meas_cov_fname'] = tmp_cfg['data']['true_cov_fname']
jobname = jobname_template.format(rmin=rmin, emu_name=emu_name)
tmp_cfg['fname'] = path.join(output_dir, jobname+'.hdf5')
with open(path.join(directory, jobname +'.yaml'), 'w') as f:
yaml.dump(tmp_cfg, f)
with open(path.join(directory, jobname + '.sbatch'), 'w') as f:
f.write(sbatch_template.format(jobname=jobname))
In [12]:
tmp_cfg = copy.deepcopy(orig_cfg)
directory = "/home/users/swmclau2/Git/pearce/bin/mcmc/config/"
output_dir = "/home/users/swmclau2/scratch/PearceMCMC/"
jobname_template = "UniverseMachine_wp_ds_rmin_{rmin}_{emu_name}"
for rmin in [None, 0.5, 1.0, 2.0]:
for emu_fname, emu_name, emu_cov in zip(emu_fnames, emu_names, emu_cov_fnames):
if rmin is not None:
tmp_cfg['emu']['fixed_params'] = {'z': 0.0, 'rmin':rmin}
tmp_cfg['emu']['training_file'] = emu_fname
tmp_cfg['emu']['emu_type'] = ['LemonPepperWet' for i in xrange(len(emu_fname))]
tmp_cfg['emu']['emu_cov_fname'] = emu_cov
tmp_cfg['data']['true_data_fname']= ['/home/users/swmclau2/Git/pearce/bin/mock_measurements/UMmock_wp.npy',
'/home/users/swmclau2/Git/pearce/bin/mock_measurements/UMmock_ds.npy']
tmp_cfg['data']['true_cov_fname'] = meas_cov_fname
tmp_cfg['data']['obs']['obs'] = ['wp','ds']
tmp_cfg['data']['obs']['rbins'] = list(r_bins)
tmp_cfg['chain']['nsteps'] = n_steps
tmp_cfg['chain']['nwalkers'] = n_walkers
tmp_cfg['chain']['mcmc_type'] = 'normal'
tmp_cfg['data']['sim']['sim_hps']['system'] = 'sherlock'
tmp_cfg['data']['cov']['emu_cov_fname'] = tmp_cfg['emu']['emu_cov_fname']
tmp_cfg['data']['cov']['meas_cov_fname'] = tmp_cfg['data']['true_cov_fname']
jobname = jobname_template.format(rmin=rmin, emu_name=emu_name)
tmp_cfg['fname'] = path.join(output_dir, jobname+'.hdf5')
with open(path.join(directory, jobname +'.yaml'), 'w') as f:
yaml.dump(tmp_cfg, f)
with open(path.join(directory, jobname + '.sbatch'), 'w') as f:
f.write(sbatch_template.format(jobname=jobname))
In [13]:
#orig_cfg_fname = '/u/ki/swmclau2//Git/pearce/bin/mcmc/nh_gg_sham_hsab_mcmc_config.yaml'
with open(orig_cfg_fname, 'r') as yamlfile:
orig_cfg = yaml.load(yamlfile)
In [14]:
tmp_cfg = copy.deepcopy(orig_cfg)
directory = "/home/users/swmclau2/Git/pearce/bin/mcmc/config/"
output_dir = "/home/users/swmclau2/scratch/PearceMCMC/"
#output_dir = "/afs/slac.stanford.edu/u/ki/swmclau2"
jobname_template = "HOD_wp_ds_rmin_{rmin}_{emu_name}"#_fixed_HOD"
for rmin in [None, 0.5, 1.0, 2.0]:
for emu_fname, emu_name, emu_cov in zip(emu_fnames, emu_names, emu_cov_fnames):
if rmin is not None:
tmp_cfg['emu']['fixed_params'] = {'z': 0.0, 'rmin':rmin}
tmp_cfg['emu']['training_file'] = emu_fname
tmp_cfg['emu']['emu_type'] = ['LemonPepperWet' for i in xrange(len(emu_fname))]
tmp_cfg['emu']['emu_cov_fname'] = emu_cov
tmp_cfg['data']['obs']['obs'] = ['wp','ds']
tmp_cfg['data']['obs']['rbins'] = list(r_bins)
tmp_cfg['data']['true_data_fname']= ['/home/users/swmclau2/Git/pearce/bin/mock_measurements/HODmock_wp.npy',
'/home/users/swmclau2/Git/pearce/bin/mock_measurements/HODmock_ds.npy']
tmp_cfg['data']['true_cov_fname'] = meas_cov_fname
tmp_cfg['data']['cov']['meas_cov_fname'] = meas_cov_fname
tmp_cfg['data']['cov']['emu_cov_fname'] = tmp_cfg['emu']['emu_cov_fname'] # TODO make this not be redundant
jobname = jobname_template.format(rmin=rmin, emu_name=emu_name)
tmp_cfg['fname'] = path.join(output_dir, jobname+'.hdf5')
tmp_cfg['sim']= {'gal_type': 'HOD',
'hod_name': 'zheng07',
'hod_params': {'alpha': 1.083,
'logM0': 13.2,
'logM1': 14.2,
'sigma_logM': 0.2,
'conc_gal_bias': 1.0},
'nd': '5e-4',
'scale_factor': 1.0,
'min_ptcl': 100,
'sim_hps': {'boxno': 1,
'downsample_factor': 1e-2,
'particles': True,
'realization': 0,
'system': 'sherlock'},
'simname': 'testbox'}
# TODO i shouldnt have to specify this this way
tmp_cfg['data']['sim'] = tmp_cfg['sim']
tmp_cfg['chain']['nwalkers'] = n_walkers
tmp_cfg['chain']['nsteps'] = n_steps
tmp_cfg['chain']['mcmc_type'] = 'normal'
# fix params during MCMC
#tmp_cfg['chain']['fixed_params'].update(tmp_cfg['sim']['hod_params'])
#try:
# del tmp_cfg['data']['true_data_fname']
# del tmp_cfg['data']['true_cov_fname']
#except KeyError:
# pass
with open(path.join(directory, jobname +'.yaml'), 'w') as f:
yaml.dump(tmp_cfg, f)
with open(path.join(directory, jobname + '.sbatch'), 'w') as f:
f.write(sbatch_template.format(jobname=jobname))
In [ ]: